package net.bingosoft.common.util;



/**
 * 2008-4-2 下午07:17:41
 * Author:yangdongyu(yangdy@bingosoft.net)
 * ReadMe:sql语句操作的帮助类
 * ChangeLog:
 */
public class SQLHelper {
	/**
	 * 检查是否是针对单表的查询,根据from和where语句之间是否有,决定,如果有认为是多表查询,否则认为是单表查询
	 * @param sql 待检查的sql语句
	 * @return boolean 是否是针对单表的查询
	 */
	public static boolean isSelectFromSingleTable(final String sql){
		String lowerSQL = sql.toLowerCase();
		int fromIndex = lowerSQL.indexOf("from");
		int whereIndex = lowerSQL.indexOf("where");
		String contentBetweenFromAndWhere = lowerSQL.substring(fromIndex + 4, whereIndex > -1 ? whereIndex : lowerSQL.length()+ whereIndex);
		return !contentBetweenFromAndWhere.contains(",");
	}
	
    /**
     * 
     * @param sqlString
     * @return
     */
    public static String sqlEscape(String sqlString){
        return StringHelper.replace(sqlString,"'","''");
    }

}
